

const electron = require('electron')
const { setWallPaperByUrl } = require('../../biz/wallpaperService/setWallPaperByUrl')

exports.initAPI = function () {
    initAppbridgeAPI()
    electron.contextBridge.exposeInMainWorld('api', {
        setWallPaperByUrl: (url, imgName) => {
            setWallPaperByUrl(url, imgName)
        }
    })
}






function initAppbridgeAPI() {
    try {
        electron.contextBridge.exposeInMainWorld('appBridge', {
            onEmit: (eventName, msgInfo) => {
                electron.ipcRenderer.send("__PUBLISH_PUSH__", eventName, msgInfo)
            },
            onListen: (eventName, fn) => {
                electron.ipcRenderer.on(eventName, (event, msgInfo) => fn(msgInfo));
            }
        })

    } catch (e) { }
}